package it.rap.application.logic;

import it.rap.applications.properties.PropertyManager;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class BusinnessLogic {
	protected EntityManagerFactory emf;
	protected EntityManager        enm;
	protected String 			   persistentUnitName;
	
	public BusinnessLogic(String persistentUnitName){
		
		
		PropertyManager properties = new PropertyManager();
		
		
		this.emf = Persistence.createEntityManagerFactory( persistentUnitName, properties.getPropertiesMap() );
		//this.emf = Persistence.createEntityManagerFactory( persistentUnitName );
		this.enm = emf.createEntityManager();
		this.persistentUnitName = persistentUnitName;
		
	}
	
	public EntityManagerFactory getEmf(){
		return emf;
	}
	
	public EntityManager getEntityManager(){
		return enm;
	}

	public void openTransaction() {
		enm.getTransaction().begin();
	}

	public void commit() {
		enm.getTransaction().commit();
	}

}
